package com.ilock.action;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ilock.bean.Ilockinfo;
import com.ilock.bean.Iuser;
import com.ilock.bean.Own;
import com.ilock.service.ILockLocService;
import com.ilock.service.ILockService;
import com.ilock.service.IUserService;
import com.opensymphony.xwork2.ActionSupport;

public class LockLocAction extends ActionSupport {
	private ILockLocService ILockLocService;
	private ILockService ILockService;
	private IUserService IUserService;
	private String useremail;
	private String userpassword;
	private String locktoken;
	private String timestamp;
	private Map<String,Object> locMap = new HashMap<String,Object>();
	
	public ILockLocService getILockLocService() {
		return ILockLocService;
	}

	public void setILockLocService(ILockLocService iLockLocService) {
		ILockLocService = iLockLocService;
	}

	public ILockService getILockService() {
		return ILockService;
	}

	public void setILockService(ILockService iLockService) {
		ILockService = iLockService;
	}

	public IUserService getIUserService() {
		return IUserService;
	}

	public void setIUserService(IUserService iUserService) {
		IUserService = iUserService;
	}

	public String getUseremail() {
		return useremail;
	}

	public void setUseremail(String useremail) {
		this.useremail = useremail;
	}

	public String getUserpassword() {
		return userpassword;
	}

	public void setUserpassword(String userpassword) {
		this.userpassword = userpassword;
	}

	public String getLocktoken() {
		return locktoken;
	}

	public void setLocktoken(String locktoken) {
		this.locktoken = locktoken;
	}

	public String getTimestamp() {
		return timestamp;
	}

	public void setTimestamp(String timestamp) {
		this.timestamp = timestamp;
	}

	public Map<String, Object> getLocMap() {
		return locMap;
	}

	public void setLocMap(Map<String, Object> locMap) {
		this.locMap = locMap;
	}

	public String getSingleLocList()throws Exception{
		System.out.println(useremail);
		Iuser iuser = checkUser();
		if(iuser!=null){
			List<Own> lockIDList = ILockService.getUserLockIDList(iuser.getIuserNumber());
			List templist = new ArrayList();
			if(timestamp!=null){
				for(int i=0;i<lockIDList.size();i++){	
					Own lockOwn = lockIDList.get(i);
					List tplist = ILockLocService.getLocklocListByTime(lockOwn.getIlockInfoNumber(), Timestamp.valueOf(timestamp));
					templist.addAll(tplist);
				}
				locMap.put("MultiLocList", templist);
				System.out.println("loc list found success");
				locMap.put("state", "success");
			}else{
				System.out.println("timestamp incompleted");
				locMap.put("state", "timestamp incompleted");
			}
		}else{
			System.out.println("user check in error");
			locMap.put("state", "user check in error");
		}
		return "success";
	}

	public String execute()throws Exception{
		
		return "success";
	}
	
	/**
	 * check user's info
	 * @return
	 */
	public Iuser checkUser(){
		Iuser iuser = null;
		iuser=IUserService.checkIn(useremail, userpassword);
		return iuser;
	}

}
